package main;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Date;
import java.util.Properties;

public class Main {

    private static Logger logger;
    private static PropertyLoader loader;

    public static void main(String[] args) {

        logger = LoggerFactory.getLogger(Main.class);
        loader = new PropertyLoader();
        Properties properties = loader.getProperties();
        File[] roots = File.listRoots();
        File system = null;

        for (File _file : roots) {
            system = _file;
            break;
        }
        if (system != null) {
            logger.info(system.getPath());
            logger.info(system.getName());
            logger.info("Free space = " + (system.getFreeSpace() / (1024 * 1024)) / 1024 + "G");  //显示GB大小
            logger.info("Usable space = " + system.getUsableSpace());
            logger.info("Total space = " + system.getTotalSpace());
            logger.info("used space  = " + (system.getTotalSpace() - system.getFreeSpace()));
            logger.info(new Date().toString());
            String hold = properties.getProperty("SizeThreshold");
            long SizeThreshold = Long.parseLong(hold) * 1024 * 1024 * 1024;
            if (system.getFreeSpace() < SizeThreshold) {
                MailToApplicant mailToApplicant = new MailToApplicant();
                mailToApplicant.setMsg("TC服务器系统" + properties.getProperty("serviceIp") + "容量不足" + hold + "G，请注意清理系统盘");
                mailToApplicant.release();
            }
        }
    }
}
